package org.me.marble;

import android.view.*;
import android.widget.*;

import android.graphics.Color;
import android.content.Context;

/**
*
* @author tungi
*/

class IconArrayAdapter<T> extends ArrayAdapter<T>{
    private T[] items;
    private Context context;

    private int[] icons;
    private int rowResource;
    private int labelResource;
    private int iconResource;

    private boolean[] enables;

    public IconArrayAdapter(Context context,int rowResource,int iconResource,
          int labelResource,int[] icons,T[] items,boolean[] enables){
        super(context, rowResource, items);
        this.context=context;
        this.rowResource=rowResource;
        this.labelResource=labelResource;
        this.iconResource=iconResource;
        this.icons=icons;
        this.items=items;
        this.enables=enables;
  }

    @Override
    public View getView(int position,View reusableView,ViewGroup parent){
        LayoutInflater inflater=(LayoutInflater)
                context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View row=inflater.inflate(this.rowResource,null);
        TextView label=(TextView)row.findViewById(this.labelResource);
        ImageView icon=(ImageView)row.findViewById(this.iconResource);
        
        if(enables[position])
            label.setTextColor(Color.WHITE);
        else
            label.setTextColor(Color.GRAY);

        label.setText((String)this.items[position]);
        icon.setImageResource(this.icons[position]);
        return row;
    }

    public void setEnable(int position,boolean enable){
        enables[position]=enable;
    }
}
